home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PRUS101.ZIP / FPRINT.PAS < prev    next >
Pascal/Delphi Source File  |  1994-12-20  |  8KB  |  454 lines

  1. unit FPRINT;
  2.  
  3.  { FIDO unit to use different Printer with ONE Unit + Driver
  4.  (*************************************************************************)
  5.  
  6.      RELEASE 1.00 - as first contained in the file PRUS101.LZH
  7.         by Matthias Tichy, 2:2440/210.14, GERMANY
  8.  
  9.            --------------------------------------------
  10.         organized for Fido's PASCAL related echoes
  11.            --------------------------------------------
  12.  
  13.      15/08/1994 to --/--/---- by Matthias Tichy, 2:2440/210.14, GERMANY
  14.  
  15.  
  16.        As far as third party copyrights are not violated this
  17.        source code is hereby placed to the public domain. Use
  18.        it whatever way you want, but use AT YOUR OWN RISK.
  19.  
  20.        In case you should modify the source rather send your
  21.        modifications to the unit's current organizer (see above for
  22.        NM address) than to spread it on your own. This will help to
  23.        keep the unit updated and grant a certain standard to all
  24.        other users as well.
  25.  
  26.        The unit is currently still under work. So it might greatly
  27.        benefit of your participation.
  28.  
  29.        Those who contributed to the following piece of source,
  30.        listed in alphabethical order:
  31.     ================================================================
  32.         Matthias Tichy ...
  33.     ================================================================
  34.        YOUR NAME WILL APPEAR HERE IF YOU CONTRIBUTE USEFUL SOURCE.
  35.  
  36.        Credits in your own programs are as welcome as unnecessary.
  37.  
  38. (***************************************************************************}
  39.  
  40. {$I FDEFINE.DEF} { Use the general include file for conditional defines and
  41.         y   common compiler directives ... }
  42.  
  43.          { ... and set the unit's specific defines aftwerwards. }
  44.  
  45. interface
  46.  
  47. uses dos, printer;
  48.  
  49. const
  50.   FPrinter : Byte = 1;
  51.   {$ifdef English}
  52.   fxxx : array[1..1] of string = ('Printer');
  53.   {$endif}
  54.   {$ifdef German}
  55.   fxxx : array[1..1] of string = ('Drucker');
  56.   {$endif}
  57.  
  58. type
  59.   PParameter = ^TParameter;
  60.   TParameter = array[1..10] of Byte;
  61.  
  62.   PTreiber = ^TTReiber;
  63.   TTreiber = array[1..30] of Char;
  64.  
  65. var
  66.   Printer_fault : byte;
  67.   f : text;
  68.   treiber_datei : string;
  69.   Parameter : PParameter;
  70.   Treiber : PTreiber;
  71.  
  72. procedure init;
  73. procedure done;
  74.  
  75. procedure setTDT(datei : string);
  76. function CheckTDT(datei : string) : boolean;
  77. function GetPrinter(datei :string) : string;
  78.  
  79. function getFault : byte;
  80. procedure Error(object_id, code : byte);
  81.  
  82. procedure laden(nr : byte);
  83. procedure ausgeben;
  84.  
  85. procedure printeln(text : string);
  86. procedure print(text : string);
  87. procedure cr;
  88. procedure lf;
  89. procedure ff;
  90.  
  91. procedure PrinterInit;
  92. procedure BoldOn;
  93. procedure BoldOff;
  94. procedure ItalicOn;
  95. procedure ItalicOff;
  96. procedure UnderLinedOn;
  97. procedure UnderLinedOff;
  98. procedure BreitOn;
  99. procedure BreitOff;
  100. procedure SchmalOn;
  101. procedure SchmalOff;
  102. procedure HighOn;
  103. procedure HighOff;
  104. procedure LowOn;
  105. procedure LowOff;
  106.  
  107. implementation
  108.  
  109. uses fstr;
  110.  
  111. function FileExists(FileName: string; attr : Word) : Boolean;
  112.  
  113. var
  114.   f: SearchRec;
  115.  
  116. begin
  117.   findfirst(Filename, attr, f);
  118.   if doserror = 0 then Fileexists := true else Fileexists := false;
  119. end;
  120.  
  121. function getpartstring(text : string; anfang, ende : char) : string;
  122.  
  123. var temp : string;
  124.     punkt : Byte;
  125.  
  126. begin
  127.   punkt := pos(anfang,text);
  128.   temp  := copy(text,punkt,length(text)-punkt);
  129.   punkt := pos(ende,temp);
  130.   if punkt <> 0 then
  131.     temp  := copy(temp,1,punkt);
  132.   getpartstring := temp;
  133. end;
  134.  
  135. procedure Init;
  136.  
  137. begin
  138.   New(Parameter);
  139.   New(treiber);
  140. end;
  141.  
  142. procedure Done;
  143.  
  144. begin
  145.   Dispose(Parameter);
  146.   Dispose(Treiber);
  147. end;
  148.  
  149. procedure setTDT(datei : string);
  150.  
  151. begin
  152.   treiber_datei := datei;
  153.   if not fileExists(treiber_datei, anyfile) then error(FPrinter, 1);
  154.   Assign(f, treiber_datei);
  155. end;
  156.  
  157. function CheckTDT(datei :string) : boolean;
  158.  
  159. var dat : text;
  160.     Zeile : string;
  161.  
  162. begin
  163.   CheckTDT := false;
  164.   assign(dat, datei);
  165.   reset(dat);
  166.   readln(dat, Zeile);
  167.   if Zeile = 'TDT' then CheckTDT := true;
  168.   close(dat);
  169. end;
  170.  
  171. function GetPrinter(datei :string) : string;
  172.  
  173. var dat : text;
  174.     Zeile : string;
  175.  
  176. begin
  177.   assign(dat, datei);
  178.   reset(dat);
  179.   repeat
  180.     readln(dat, Zeile);
  181.   until copy(Zeile,1,2) = 'N)';
  182.   getPrinter := copy(Zeile, 4, length(Zeile)-4);
  183.   close(dat);
  184. end;
  185.  
  186. function getfault : byte;
  187.  
  188. begin
  189.   Printer_fault := ioresult;
  190.   if Printer_fault <> 0 then Error(FPrinter, Printer_fault);
  191.   getfault := Printer_fault;
  192. end;
  193.  
  194. procedure Error(object_id, code : Byte);
  195.  
  196. begin
  197.   writeln;
  198.   writeln('Fehler im Modul FPRINT : ', fxxx[object_id],' Nr: ', code);
  199.   halt(code);
  200. end;
  201.  
  202. procedure setparameter(index, Text : byte);
  203.  
  204. begin
  205.   Parameter^[index] := text;
  206. end;
  207.  
  208. procedure laden(nr :Byte);
  209.  
  210. var
  211.   punkt : LongInt;
  212.   buf : String;
  213.   ch : string;
  214.   dummy : string;
  215.   para : Char;
  216.   tester : boolean;
  217.   param : Byte;
  218.  
  219.   function getchar : char;
  220.  
  221.   var temp : string;
  222.       dummy : Byte;
  223.       i : Byte;
  224.       code : Integer;
  225.  
  226.   begin
  227.     buf := removeleft(') ',buf);
  228.     buf := removeright('; ',buf);
  229.     if buf = '' then
  230.       begin
  231.         getChar := #255;
  232.         exit;
  233.       end;
  234.     temp := buf;
  235.     i := 1;
  236.     while (not (temp[i] in ['#','$','n'])) and not (i>length(temp)) do inc(i);
  237.     if temp[length(temp)] <> ' ' then temp := temp + ' ';
  238.     temp := getpartstring(temp,temp[i],' ');
  239.     case temp[1] of
  240.       '#' : begin
  241.               i := 2;
  242.               if temp[length(temp)] <> ' ' then temp := temp + ' ';
  243.               val(copy(temp,2,length(temp)-2),dummy,code);
  244.               getChar := char(dummy);
  245.             end;
  246.       'n' : begin
  247.               getChar := char(parameter^[param]);
  248.               inc(param);
  249.             end;
  250.       ' ' : begin
  251.               getChar := #255;
  252.             end;
  253.     end;
  254.     i := pos(' ',buf);
  255.     buf := copy(buf, i, length(buf)-i+1);
  256.     if i = 0 then buf := '';
  257.   end;
  258.  
  259. begin
  260.   for punkt := 1 to 35 do treiber^[punkt] := #255;
  261.   param := 1;
  262.   str(nr,ch);
  263.   reset(f);
  264.   tester := false;
  265.   repeat
  266.     readln(f, buf);
  267.     dummy := buf;
  268.     buf := removeLeft(' ',buf);
  269.     buf := copy(buf, 1, pos(')',buf)-1);
  270.     if buf = ch then tester := true;
  271.     buf := dummy;
  272.   until tester = true or eof(f);
  273.   if eof(f) and not tester then
  274.     begin
  275.       writeln('Fehler in Druckertreiber bei Nr :', nr, '!!');
  276.       halt;
  277.     end;
  278.   buf := getpartstring(buf,')',';');
  279.   punkt := 1;
  280.   repeat
  281.     para := getChar;
  282.     if para <> #255 then Treiber^[punkt] := para;
  283.     inc(punkt);
  284.   until para = #255;
  285.   close(f);
  286. end;
  287.  
  288. {$I-}
  289. procedure ausgeben;
  290.  
  291. var
  292.   index : byte;
  293.  
  294. begin
  295.   for index := 1 to 35 do if Treiber^[index] <> chr(255) then
  296.     begin
  297.       repeat;
  298.         write(lst,Treiber^[index]);
  299.       until getfault = 0;
  300.     end;
  301. end;
  302.  
  303. procedure printeln(text : string);
  304.  
  305. var i : Byte;
  306.  
  307. begin
  308.   repeat;
  309.   writeln(lst,text);
  310.   until getfault = 0;
  311. end;
  312.  
  313. procedure print(Text : string);
  314.  
  315. var i : Byte;
  316.  
  317. begin
  318.   repeat;
  319.   write(lst,text);
  320.   until getfault = 0;
  321. end;
  322.  
  323. {$I+}
  324.  
  325. procedure PrinterInit;
  326.  
  327. begin
  328.   laden(1);
  329.   ausgeben;
  330. end;
  331.  
  332. procedure BoldOn;
  333.  
  334. begin
  335.   laden(2);
  336.   ausgeben;
  337. end;
  338.  
  339. procedure BoldOff;
  340.  
  341. begin
  342.   laden(3);
  343.   ausgeben;
  344. end;
  345.  
  346. procedure ItalicOn;
  347.  
  348. begin
  349.   laden(8);
  350.   ausgeben;
  351. end;
  352.  
  353. procedure ItalicOff;
  354.  
  355. begin
  356.   laden(9);
  357.   ausgeben;
  358. end;
  359.  
  360. procedure UnderLinedOn;
  361.  
  362. begin
  363.   laden(4);
  364.   ausgeben;
  365. end;
  366.  
  367. procedure UnderLinedOff;
  368.  
  369. begin
  370.   laden(5);
  371.   ausgeben;
  372. end;
  373.  
  374. procedure cr;
  375.  
  376. begin
  377.   repeat
  378.     write(lst, #13);
  379.   until getfault = 0;
  380. end;
  381.  
  382. procedure lf;
  383.  
  384. begin
  385.   repeat
  386.     write(lst, #10);
  387.   until getfault = 0;
  388. end;
  389.  
  390. procedure ff;
  391.  
  392. begin
  393.   repeat
  394.     write(lst, #12);
  395.   until getfault = 0;
  396. end;
  397.  
  398. procedure BreitOn;
  399.  
  400. begin
  401.   laden(6);
  402.   ausgeben;
  403. end;
  404.  
  405. procedure BreitOff;
  406.  
  407. begin
  408.   laden(7);
  409.   ausgeben;
  410. end;
  411.  
  412. procedure SchmalOn;
  413.  
  414. begin
  415.   laden(14);
  416.   ausgeben;
  417. end;
  418.  
  419. procedure SchmalOff;
  420.  
  421. begin
  422.   laden(15);
  423.   ausgeben;
  424. end;
  425.  
  426. procedure HighOn;
  427.  
  428. begin
  429.   laden(10);
  430.   ausgeben;
  431. end;
  432.  
  433. procedure HighOff;
  434.  
  435. begin
  436.   laden(11);
  437.   ausgeben;
  438. end;
  439.  
  440. procedure LowOn;
  441.  
  442. begin
  443.   laden(12);
  444.   ausgeben;
  445. end;
  446.  
  447. procedure LowOff;
  448.  
  449. begin
  450.   laden(13);
  451.   ausgeben;
  452. end;
  453.  
  454. end.